// 弹窗位置边界判断
export const fixBounding = (id: string, styleObj: any) => {
  const dom = document.getElementById(id)
  if (dom != null) {
    const rectObj = dom?.getBoundingClientRect()
    if (rectObj.top < 3.375) {
      styleObj.bottom = undefined
      styleObj.top = '3.375rem'
    } else if (window.innerHeight - rectObj.bottom < 0) {
      styleObj.top = undefined
      styleObj.bottom = 0
    }
    if (rectObj.left < 0) {
      styleObj.right = undefined
      styleObj.left = 0
    } else if (window.innerWidth - rectObj.right < 0) {
      styleObj.left = undefined
      styleObj.right = 0
    }
  }
}

// 路由格式化
export const formatRouterPath = (menus: any[], path: string) => {
  menus.forEach((i) => {
    // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
    i.path = `${path}/${i.path}`
    if (i.children.length > 0) {
      formatRouterPath(i.children, i.path)
    }
  })
}
